package org.unisannio.remote;

import org.unisannio.util.ServiceInfo;

import it.unipr.ce.dsg.s2p.sip.Address;
import android.content.Context;
/**
 * Generic communicator class for remote peers
 * 
 * @author Fabio Melillo
 *
 */
public class GenericRemote {
	
	protected BroadcastContentPeer broadcastContentPeer;
	protected Context context;
	
	public GenericRemote(Context context){
		broadcastContentPeer=BroadcastContentPeer.getInstance(context);
		this.context=context;
	}
	
	public GenericRemote(Context context, int port) {
		broadcastContentPeer=BroadcastContentPeer.getInstance(context, port);
		this.context=context;
	}
	
	/**
	 * Sets the server address
	 * N.B. the ":" must be used only for separating IP address from PORT
	 * 
	 * @param indirizzo - e.g. peer2@192.168.1.25:7564
	 */
	public void setServer(String indirizzo){
		broadcastContentPeer.setSuperPeer(new Address(indirizzo));
	}
	
	/**
	 * Gets the serverAddress
	 * 
	 * @return the ServerAddress, null if no ServerAddress is set
	 */
	public Address getServerAddress(){
		return broadcastContentPeer.getSuperPeer();
	}
	
	/**
	 * Send the message directly to the SuperPeer
	 * 
	 * @param sinfo - service you want to publish/subscribe
	 * @param typeOfRequest - numeric type [Converter.PUBLISH or RETRACT]
	 */
	public void sendToSuperPeer(ServiceInfo sinfo, int typeOfRequest){
		broadcastContentPeer.sendToSuperPeer(sinfo, typeOfRequest);
	}
	
	/**
	 * Gets the sip address of the device.
	 * No other method to grab that.
	 * 
	 * @return the device Address
	 */
	public Address getAddress(){
		return broadcastContentPeer.getAddress();
	}
	
}
